<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>新建工人花名册</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">

        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>身份证号</label>
                        <div class="layui-input-block">
                            <input type="text" name="idcard" id="idcard" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>联系电话</label>
                        <div class="layui-input-block">
                            <input type="text" name="tel" id="tel" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>用工性质</label>
                        <div class="layui-input-block">
                            <select id="yongxing" name="yongxing" lay-filter="yongxing" ></select>
                            <p class="error" id="yongxing_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">班组</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="banid" class="layui-input banid" onclick="openPage('../public/choose_labour_ban.php?dom=banid&page=labour_gong','80%','80%');">
                            <div class="choose_div" id="banid" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_labour_ban.php?dom=banid&page=labour_gong','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工种</label>
                        <div class="layui-input-block">
                            <div id="gongtype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工资类型</label>
                        <div class="layui-input-block">
                            <select id="gonglei" name="gonglei" lay-filter="gonglei" ></select>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工价</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongfee" id="gongfee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">所在地区</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">开户行</label>
                        <div class="layui-input-block">
                            <input type="text" name="bankname" id="bankname" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">银行卡号</label>
                        <div class="layui-input-block">
                            <input type="text" name="banknum" id="banknum" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    $("#commentForm").validate({
        rules: {
            name: {required: true},
            idcard: {required: true},
            tel: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            idcard: {required: "请输入"},
            tel: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_labour_gong_add}).done(function(res){
            if (res.code === 2000) {

                load_areas('areas', res.data.areas, 3);

                var yongxing_str = '<option value="">请选择</option>';
                var yongxing = res.data.yongxing;
                for (var key in yongxing){
                    yongxing_str += '<option value="'+yongxing[key]+'">'+yongxing[key]+'</option>';
                }
                $("#yongxing").html(yongxing_str);

                xmselect_dan('gongtype', res.data.gongtype, '', function (res) {
                    if(res.arr && res.arr.length > 0){
                        $("#gongtype").find('xm-select').removeClass('error');
                    }else{
                        $("#gongtype").find('xm-select').addClass('error');
                    }
                });

                var gonglei_str = '<option value="">请选择</option>';
                var gonglei = res.data.gonglei;
                for (var key in gonglei){
                    gonglei_str += '<option value="'+gonglei[key]+'">'+gonglei[key]+'</option>';
                }
                $("#gonglei").html(gonglei_str);

                initParseMoney();
                public_upload_file_load('upload_files');
                render_from();
            }
        });

        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#yongxing_error').show().text('请选择');
                $('#yongxing_error').parent().find('input').addClass('select_error');
            }else{
                $('#yongxing_error').hide();
                $('#yongxing_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            data.field.banid = get_choose_val('banid');

            var validRes = $("#commentForm").valid();
            if(data.field.yongxing == ''){
                $('#yongxing_error').show().text('请选择');
                $('#yongxing_error').parent().find('input').addClass('select_error');
                validRes = false;
            }else{
                $('#yongxing_error').hide();
                $('#yongxing_error').parent().find('input').removeClass('select_error');
            }

            if(!data.field.gongtype){
                $("#gongtype").find('xm-select').addClass('error');
                validRes = false;
            }else{
                $("#gongtype").find('xm-select').removeClass('error');
            }

            if(!validRes){return false;}


            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_labour_gong_add, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
